﻿var images = 0;

layui.use(['form', 'upload', 'layer'], function () {
    var $ = layui.jquery
    , form = layui.form();

    layui.upload({
        url: '/Store/UpLoadImg'
        , method: 'post'
        ,ext:'jpg|png'
        ,before: function (input) {
            layer.msg("正在上传");
        }
        , success: function (res, input) {
            if (res != null) {
                $(".imgs").append("<input type='hidden'name='Images[" +images + "].Id' value=' " + res.Id + "'/>   <img class='zoom-img' src='" + res.AttachmentPath + "'/>");
                images++;
            }
            layer.closeAll();
        }
    })

    //监听提交
    form.on('submit(bt-submit)', function (data) {
        var category = $('select').val();
        data.field.category = category;
        var index = layer.load();
        $.ajax({
            url: "/Store/AddGoods",
            data: data.field,
            method:'post',
            success: function (data) {
                if (data.success != null) {
                    layer.msg(data.success);
                }
                else {
                    layer.msg(data.error);
                }
                layer.close(index);
            },
            error: function () {
                layer.msg("服务端出错了");
                layer.close(index);
            }
        });
        return false;
    });
})